package com.example.danangtravel.Hotel;

import java.io.IOException;
import java.util.ArrayList;

import com.exam.danangtranel.adapter.TbHotelAdapter;
import com.exam.danangtranel.filed.Hotel;
import com.example.danangtravel.DataAccess;
import com.example.danangtravel.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class HotelActivity extends Activity {
	private ListView lvHotel;
	private TbHotelAdapter adapter;
	private ArrayList<Hotel> dataArr;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_hotel);
		DataAccess db = null;
		try {
			db = new DataAccess(this);
			dataArr = db.getAllHotel("1");
			db.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		adapter = new TbHotelAdapter(this, dataArr);
		lvHotel = (ListView) findViewById(R.id.lvHotel);
		lvHotel.setAdapter(adapter);

		lvHotel.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent innter = new Intent(view.getContext(),
						HotelDetailActivity.class);
				innter.putExtra("ID", dataArr.get(position).getID());
				startActivity(innter);
			}
		});
	}
}
